package app.context;

import org.ricks.net.AioSession;
import org.ricks.net.Listener;

import java.io.IOException;
import java.nio.ByteBuffer;

/**
 * @author chenwei
 * @Title:
 * @Package
 * @Description:
 * @date 2022/12/1618:05
 */
public class NetListener implements Listener {
    @Override
    public void onConnected(AioSession session) {
        System.err.println(session.getSessionID());
        byte[] bytes = new byte[]{12,0,0,0,0,0,6,0,8,0,4,0,6,0,0,0,1,0,0,0};
        try {
            session.writeBuffer().writeInt(2 + bytes.length);
            session.writeBuffer().writeShort((short) 901);
            session.writeBuffer().writeAndFlush(bytes);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void handleReceive(ByteBuffer byteBuf, AioSession session) {

    }

    @Override
    public void handleException(Throwable ex, AioSession session) {

    }

    @Override
    public void handleClose(AioSession session) {

    }
}
